package edu.arizona.eller.mis.liferoulette;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class main extends Activity implements OnClickListener  {
    /** Called when the activity is first created. */
	
	Button bToDo;
	Button bFood;
	Button bAdv;
	
	TextView welcomeText;
	
//	LocUtility locUtility;
//	LocationManager locManager;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        bToDo = (Button)findViewById(R.id.toDoButton);
        bToDo.setOnClickListener(this);
        bFood = (Button)findViewById(R.id.foodButton);
        bFood.setOnClickListener(this);
        bAdv = (Button)findViewById(R.id.advButton);
        bAdv.setOnClickListener(this);
        
        welcomeText = (TextView)findViewById(R.id.welcomeText);
        
//        locManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
//        locUtility = new LocUtility(locManager);
        
        SharedPreferences myPrefs = this.getSharedPreferences("lrPrefs", MODE_PRIVATE);
        String userName = myPrefs.getString("un_pref", null);
        
        if(userName == null){
        	startActivity(new Intent(this, UserPreferenceAcvitity.class));
        }else{
        	welcomeText.setText("Welcome - " +userName);
        }
    }
   

	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu, menu);
	    return true;
	}
	
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	        case R.id.settingsItem:     
	        	startActivity(new Intent(this, UserPreferenceAcvitity.class));
	            break;
	        case R.id.historyItem:     
	        	startActivity(new Intent(this, HistoryActivity.class));
	            break;
	    }
	    return true;
	}

	public void onClick(View v) {
		// TODO Auto-generated method stub
		Intent i = new Intent(this,result.class);
		if(v == bToDo){
			i.putExtra("type", "night_club|movie_theater|mall|zoo");
		}else if(v == bFood){
			i.putExtra("type", "restaurant");
		}else if(v == bAdv){
			i.putExtra("type", "amusement_park|bar|subway_station|stadium");
		}
		startActivity(i);
	}


}